// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'   //路由
import { Toast } from 'vant';    //提示框
import common from './assets/js/common.js'    //公共文件
import filter from './assets/js/filter'   //过滤器
import axios from "axios"   //axios服务请求
import qs from "qs"
import md5 from 'md5'   //md5加密
import NProgress from 'nprogress'
import 'lib-flexible'  //  引入 lib-flexible
import './../src/assets/css/base.css' //加载base.css
import 'vant/lib/vant-css/index.css'   //全局引用vant样式
import './../src/assets/css/font-awesome.min.css'  //引用字体图标样式
import 'nprogress/nprogress.css'


/*全局注册*/
Vue.config.productionTip = false
Vue.prototype.Tools = common.tools; //全局注册，在所有组件里都可调用common.js里的公共方法
Vue.prototype.axios = axios;
Vue.prototype.qs = qs;
Vue.prototype.md5 = md5;

// 判断是否登录
router.beforeEach((to, from, next) => {
    let url = to.path.indexOf('login') > -1 || to.path.indexOf('register') > -1 || to.path.indexOf('revisePassword') > -1 || to.path.indexOf('down') > -1;
    let token = window.localStorage.getItem('token');

  NProgress.done();
  next()

    // if (!token && !url) {
    //     Toast({type : 'text', message :'请登录', position: 'middle', duration: 2000});
    //     next('/login')
    // } else {
    //     NProgress.done();
    //     next()
    // }
})

// router.afterEach(transition => {
//     NProgress.done();
// });


//全局过滤器 filter
for (var k in filter) {
    Vue.filter(k, filter[k]);
};

/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    template: '<App/>',
    components: { App }
})
